package com.study.design.pattern.pattern.behavioral.memento;

/**
 * @Author: gongsl
 * @Date: 2025-03-24 21:56
 * @description: 原发器类：文本编辑器
 */
public class TextEditor {

    private String text = "";

    public void write(String newText) {
        text = newText;
    }

    public String getText() {
        return text;
    }

    /**
     * 保存当前状态
     */
    public Memento save() {
        return new Memento(text);
    }

    /**
     * 恢复到之前的状态
     */
    public void restore(Memento memento) {
        text = memento.getState();
    }
}
